<?php
namespace Kuoqi\Html;
//简单的编辑器
class Editor{

    public $codes = array();//代码块保存的地方

    public function addLinelimit(){
        $row = new Page\Row();
        $row->format = 'line-limit';
        $this->codes[] = $row;
    }

    public function addRow($rowObj){
        $this->codes[] = $rowObj;
    }

    public function addRowtitle($stream){
        $row = new Page\Row();
        $row->format = 'title';
        $row->addItem($stream);
        $this->codes[] = $row;
    }

    public function addRowtext($stream = ''){
        $row = new Page\Row();
        $row->addItem($stream);
        $this->codes[] = $row;
    }

    public function addRowcode($stream = ''){
        $row = new Page\Row();
        $row->format = 'code';
        $row->addItem($stream);
        $this->codes[] = $row;
    }

    //增加提示语句
    public function addRowtips($stream = ''){
        $row = new Page\Row();
        $row->format = 'tips';
        $row->addItem($stream);
        $this->codes[] = $row;
    }

    static public function createRow(){
        return new Page\Row();
    }

    //创建一个api模块的信息
    static public function addApi($config = array()){
        return new Page\CodeApi($config);
    }

    public function flush(){
        $stream = '';
        foreach($this->codes as $item){
            $stream .= $item->flush();
        }
        return $stream;
    }

}